﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace IntfSetting
{
    public partial class FrmSetWebService : Form
    {
        public FrmSetWebService(string ID,DataTable datWebService)
        {
            InitializeComponent();
            this.datWebService = datWebService;
            if (!(ID.Equals(string.Empty)))
            {
                dataRows = datWebService.Select("ID = " + ID);
                txtCode.Text = dataRows[0]["SysCode"].ToString();
                txtName.Text = dataRows[0]["Address"].ToString();

                txtCode.ReadOnly = true;
                blnNew = false;

            }
        }

        public DataTable datWebService = new DataTable();
        private Boolean blnNew = true;
        private DataRow[] dataRows = new DataRow[1];
        private void btnCancle_Click(object sender, EventArgs e)
        {
            //datWebService.Clear();
            this.Dispose();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!CheckData())
            {
                return;
            }

            if (blnNew)
            {
                DataRow dataRow = datWebService.NewRow();
                dataRow["SysCode"] = txtCode.Text;
                dataRow["Address"] = txtName.Text;

                datWebService.Rows.Add(dataRow);

    
            }
            else
            {
                dataRows[0]["SysCode"] = txtCode.Text.Trim();
                dataRows[0]["Address"] = txtName.Text.Trim();
            }
            this.Dispose();
        }

        private Boolean CheckData()
        {
            try
            {
                Boolean blnReturn = true;
                if (txtCode.Text.Trim().Equals(string.Empty))
                {
                    MessageBox.Show("编号不可为空");
                    txtCode.Focus();
                    return false;
                }

                if (txtName.Text.Trim().Equals(string.Empty))
                {
                    MessageBox.Show("名称不可为空");
                    txtName.Focus();
                    return false;
                }

                return blnReturn;

            }
            catch (Exception)
            {
                return false;
                throw;
            }
        }

    }
}
